<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>async</title>

</head>

<body>

   

    <script>

        function beiliao(){

            console.log("开始备料,预计用时5秒");

            return new Promise(function(resolve,reject){

                setTimeout(resolve,5000,"mima");

            });

        }

        function tiqu(pwd){

            if(pwd!="mima"){console.log("提取密码错误");

            return false;

        }

            console.log("开始取备料,预计用时2秒");

            return new Promise(function(resolve,reject){

                setTimeout(resolve,2000,"已取");

            });

        }

        function huomian(){

            console.log("开始和面,预计用时7秒");

            return new Promise(function(resolve,reject){

                setTimeout(resolve,7000,"和面完成");

            });

        }

        function huoxian(){

            console.log("开始和馅,预计用时4秒");

            return new Promise(function(resolve,reject){

                setTimeout(resolve,4000,"和馅");

            });

        }

        function baojiaozi(){

            console.log("开始包饺子,预计用时6秒");

            return new Promise(function(resolve,reject){

                setTimeout(resolve,6000,"包饺子");

            });

        }

        async function dp(){

            // try{

                let pwd=beiliao();//购买原料

            console.log("原料已放置存取柜，请凭密码提取");

            await tiqu("mima");//提取购买的原料

            console.log("提取原料完成，可以开始了！")

            await Promise.all([huomian(),huoxian()]);

            console.log("和面和和馅")

            await baojiaozi;

            console.log("饺子包完了，煮了就可以吃！");

            return "chi!";

            // }

            // catch(error){

            //     console.log(error);

            //     }

        }

        dp().then(v=>{console.log(v);});

    </script>

</body>

</html>